<?php
namespace app\api\model\order;
use think\facade\Db;

class ShadowOrder{
	
	public function insertOrderOperation($_data)
	{
		return Db::name("shadow_order_operation")->insert($_data,true);
	}
	public function insertOrderDetails($_data)
	{
		return Db::name("shadow_order_details")->insert($_data,true);
	}
	
	public function insertOrder($_data){
		return Db::name("shadow_order")->insert($_data,true);
	}
	
	public function insertOrderAddr($_data){
		return Db::name("shadow_order_addr")->insert($_data,true);
	}
	
	public function insertOrderCore($_data)
	{
		return Db::name("shadow_core_pay")->insert($_data,true);
	}
	
	
	public function findWroksData($_where,$_field)
	{
		return Db::name('opus')->where($_where)->field($_field)->find();
	}
	
	public function findOrder($_where,$_field)
	{
		return Db::name("shadow_order")->where($_where)->field($_field)->find();
	}
	
	public function findOrderData($_where,$_field){
		return Db::name("shadow_order")->alias("o")
				->join("opus opus","o.opus_id=opus.id")
				->where($_where)
				->field($_field)
				->find();
	}
	
	public function findOrderCorePay($_where,$_field)
	{
		return Db::name("shadow_core_pay")->where($_where)->field($_field)->find();
	}
	
	public function findOrderDetails($_where,$_field)
	{
		return Db::name("shadow_order")->alias("o")
					->join("opus opus","opus.id=o.opus_id")
					->join("shadow_order_addr addr","addr.id=o.addr_id")
					->where($_where)
					->field($_field)
					->find();
	}
	/**
	 * @title 查找订单物流对应的数据来获取物流数据
	 */
	public function findOrderLogistics($_where,$_field){
		return Db::name("shadow_order_details")->alias("d")
			->join("logistics_company c","d.company_id=c.id")
			->where($_where)
			->field($_field)
			->find();
	}
	
	public function selectOrderData($_where,$_field,$_limit,$_order)
	{
		$_data=Db::name("shadow_order")->alias("o")
				->join("opus opus","opus.id=o.opus_id")
				->where($_where)
				->field($_field)
				->order($_order)
				->limit(current($_limit),next($_limit))
				->select();
		return !empty($_data)?$_data->toArray():[];		
	}
	
	public function updateOrder($_up,$_where)
	{
		return Db::name("shadow_order")->where($_where)->update($_up);
	}
	
	public function upOrderCorePay($_up,$_where){
		return Db::name("shadow_core_pay")->where($_where)->update($_up);
	}
	public function selectOrder($_where,$_field,$_limit)
	{
		$_data=Db::name("shadow_order")->where($_where)->field($_field)->limit(reset($_limit),end($_limit))->select();
		return !empty($_data)?$_data->toArray():[];
	}
	
	
	
	public function selectOperationLog($_where,$_field,$_order="id asc"){
		$_data=Db::name("shadow_order_operation")->where($_where)->field($_field)->order($_order)->select();
		return !empty($_data)?$_data->toArray():[];
	}
	
	
}
?>